package cn.chen.controller;

import cn.chen.common.aop.LogAnnotation;
import cn.chen.service.ArticleService;
import cn.chen.vo.Result;
import cn.chen.vo.params.ArticleParam;
import cn.chen.vo.params.PageParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("articles")
public class ArticleController {

    @Autowired
    ArticleService articleService;
    /**
     * 首页 文章列表
     * @param pageParams
     * @return
     */
    //记日志
    @LogAnnotation(module="文章",operator="获取文章列表")
    @PostMapping
    public Result articles(@RequestBody PageParams pageParams){
//        int i=10/0;
        return  articleService.listArticle(pageParams);
    }

    /**
     * 首页 最热文章
     */
    @PostMapping("hot")
    public Result hotArticle(){
        int limit =5;
        return articleService.hotArticle(limit);
    }

    /**
     * 首页 最新文章
     */
    @PostMapping("new")
    public Result newArticle(){
        int limit=5;
        return articleService.newArticles(limit);
    }
    /**
     * 首页 文章归档
     * @return
     */
    @PostMapping("listArchives")
    public Result listArchives(){
        return articleService.listArchives();
    }


    /**
     * 文章详情
     */
    @PostMapping("view/{id}")
    public Result findArticleById(@PathVariable("id") String id){
         return articleService.findArticleById(id);
    }

    /**
     * 发布文章
     */
    @PostMapping("publish")
    public Result publish(@RequestBody ArticleParam articleParam){
        return articleService.publish(articleParam);
    }
}
